function [keyPress, keyCodes, keyTimes]= Kb_bcoe(abs_start_time)
% function [pressed, ctime, cchar]= Kb_bcoe([abs_start_time])
% abs_start_time in seconds just like GetSecs
% abs_start_time=getsecs;
% see also Kb_bcoeMS
% bcoe 2012-aug-01

if nargin==0
    abs_start_time=0;
    tscale=1;
else
    tscale=1000;
end

%[keyPress, firstPress, firstRelease, lastPress, lastRelease]=KbQueueCheck_internal(); %#ok<ASGLU,NASGU>
[keyPress, firstPress, firstRelease, lastPress, lastRelease] = PsychHID('KbQueueCheck');%#ok<ASGLU,NASGU>

if keyPress
    keyTimes=[max([0,firstPress(firstPress>0)-abs_start_time]),...
        max([0,lastPress(lastPress>0)-abs_start_time])]*tscale;
    keyCodes=[max([0,find(firstPress>0)]),...
        max([0,find(lastPress>0)])];
else
    keyTimes=[0,0];
    keyCodes=[0,0];
end
%cchar=char(ccode);
end
% function [pressed, firstPress, firstRelease, lastPress, lastRelease]=KbQueueCheck_internal
% % a no check version to save time
% [pressed, firstPress, firstRelease, lastPress, lastRelease] = PsychHID('KbQueueCheck');
% 
% % % Any dead keys defined?
% % ptb_kbcheck_disabledKeys=[];
% % if ~isempty(ptb_kbcheck_disabledKeys)
% %     % Yes. Disable all dead keys - force them to 'not ever pressed or released':
% %     firstPress(ptb_kbcheck_disabledKeys)=0;
% %     firstRelease(ptb_kbcheck_disabledKeys)=0;
% %     lastPress(ptb_kbcheck_disabledKeys)=0;
% %     lastRelease(ptb_kbcheck_disabledKeys)=0;
% %     
% %     % Reevaluate global key down state:
% %     pressed = any(firstPress);
% % end
% end
% 
% 

